package junit.com.cpi.cornpp.common.files;

import java.util.List;

import com.cpi.cornpp.common.files.SAPComponentCornCost;
import com.cpi.cornpp.common.files.SAPComponentExchangeRate;
import com.cpi.cornpp.common.files.SAPComponentInternalOrder;
import com.cpi.cornpp.common.files.SAPComponentPurchaseOrder;
import com.cpi.cornpp.common.files.exception.SAPComponentFileException;

import junit.framework.TestCase;

public class SAPComponentCornCostTest extends TestCase {

	private static final String FILE_NAME = "CornCost.txt";
	private static final String FILE_NAME_EXCHANGE_RATE = "ExchangeRates.txt";
	private static final String FILE_NAME_INTERNAL_ORDER = "InternalOrders.txt";
	private static final String FILE_NAME_PURCHASE_ORDER = "PO.txt";

	SAPComponentCornCost  sapComponentCornCost = null;
	SAPComponentExchangeRate sapComponentExchangeRate = null;
	SAPComponentInternalOrder sapComponentInternalOrder = null;
	SAPComponentPurchaseOrder sapComponentPurchaseOrder = null;
	
	public SAPComponentCornCostTest(String name) {
		super(name);
	}

	protected void setUp() throws Exception {
		sapComponentCornCost = new SAPComponentCornCost(FILE_NAME);
		sapComponentExchangeRate = new SAPComponentExchangeRate(FILE_NAME_EXCHANGE_RATE);
		sapComponentInternalOrder = new SAPComponentInternalOrder(FILE_NAME_INTERNAL_ORDER);
		sapComponentPurchaseOrder = new SAPComponentPurchaseOrder(FILE_NAME_PURCHASE_ORDER);
	}

	protected void tearDown() throws Exception {
		sapComponentCornCost = null;
		sapComponentExchangeRate = null;
		sapComponentInternalOrder = null;
		sapComponentPurchaseOrder = null;
	}

	public void testParse() {
		List fileLines = null;
		List fileDTOs = null;
		int totalFile = 0;
		int totalImported = 0;
		try {
			if(sapComponentCornCost.exists()){
				fileLines = sapComponentCornCost.getContent();
				totalFile = sapComponentCornCost.size();
				fileDTOs = sapComponentCornCost.parse(fileLines);
				totalImported = sapComponentCornCost.insertAll(fileDTOs);
				System.out.println("Summary-> total: " + totalFile + " ; imported : "+ totalImported);
			}
		} catch (SAPComponentFileException e) {
			e.printStackTrace();
			fail(e.getMessage());
		}
	}

	public void testInsertAll() {
		List fileLines = null;
		List fileDTOs = null;
		int totalFile = 0;
		int totalImported = 0;
		try {
			if(sapComponentExchangeRate.exists()){
				fileLines = sapComponentExchangeRate.getContent();
				totalFile = sapComponentExchangeRate.size();
				fileDTOs = sapComponentExchangeRate.parse(fileLines);
				totalImported = sapComponentExchangeRate.insertAll(fileDTOs);
				System.out.println("Summary-> total: " + totalFile + " ; imported : "+ totalImported);
			}
		} catch (SAPComponentFileException e) {
			e.printStackTrace();
			fail(e.getMessage());
		}
	}

	public void testSAPComponentFile() {
		List fileLines = null;
		List fileDTOs = null;
		int totalFile = 0;
		int totalImported = 0;
		try {
			if(sapComponentInternalOrder.exists()){
				fileLines = sapComponentInternalOrder.getContent();
				totalFile = sapComponentInternalOrder.size();
				fileDTOs = sapComponentInternalOrder.parse(fileLines);
				totalImported = sapComponentInternalOrder.insertAll(fileDTOs);
				System.out.println("Summary-> total: " + totalFile + " ; imported : "+ totalImported);
			}
		} catch (SAPComponentFileException e) {
			e.printStackTrace();
			fail(e.getMessage());
		}
	}

	public void testExists() {
		List fileLines = null;
		List fileDTOs = null;
		int totalFile = 0;
		int totalImported = 0;
		try {
			if(sapComponentPurchaseOrder.exists()){
				fileLines = sapComponentPurchaseOrder.getContent();
				totalFile = sapComponentPurchaseOrder.size();
				fileDTOs = sapComponentPurchaseOrder.parse(fileLines);
				totalImported = sapComponentPurchaseOrder.insertAll(fileDTOs);
				System.out.println("Summary-> total: " + totalFile + " ; imported : "+ totalImported);
			}
		} catch (SAPComponentFileException e) {
			e.printStackTrace();
			fail(e.getMessage());
		}
	}

	public void testGetContent() {
		fail("Not yet implemented");
	}

}
